package com.weijian.demo1.mapper;

import com.weijian.demo1.entity.Document;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DocumentMapper {

    @Insert("INSERT INTO documents (title, content, team_id, created_by, last_modified_by, created_at, updated_at, version) " +
            "VALUES (#{title}, #{content}, #{teamId}, #{createdBy}, #{lastModifiedBy}, #{createdAt}, #{updatedAt}, #{version})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Document document);

    @Select("SELECT * FROM documents WHERE team_id = #{teamId}")
    List<Document> findByTeamId(Long teamId);

    @Select("SELECT * FROM documents WHERE id = #{id}")
    Document findById(Long id);

    @Update("UPDATE documents SET title = #{title}, content = #{content}, last_modified_by = #{lastModifiedBy}, " +
            "updated_at = #{updatedAt}, version = #{version} WHERE id = #{id}")
    void update(Document document);

    @Delete("DELETE FROM documents WHERE id = #{id}")
    void delete(Long id);
}